package com.zhang.authority.controller;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2024-07-10 16:46
 **/
@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @Resource
    private AuthenticationManager authenticationManager;
//
//    @Resource
//    private TokenStore tokenStore;
//
//    @Resource
//    private JwtAccessTokenConverter accessTokenConverter;
//
//    @PostMapping("/login")
//    public ResponseEntity<?> login(@RequestParam String username, @RequestParam String password) {
//        try {
//            // 使用 AuthenticationManager 进行认证
//            Authentication authentication = authenticationManager.authenticate(
//                    new UsernamePasswordAuthenticationToken(username, password)
//            );
//
//            // 认证成功生成令牌
//            SecurityContextHolder.getContext().setAuthentication(authentication);
//            OAuth2AccessToken accessToken = accessTokenConverter.enhance(
//                    tokenStore.getAccessToken((OAuth2Authentication) authentication)
//            );
//
//            // 返回令牌给客户端
//            return ResponseEntity.ok(accessToken);
//        } catch (AuthenticationException e) {
//            // 处理认证失败的情况
//            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
//        }
//    }
}

